# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:chrome_test.py
@Time:2024/10/11 15:50

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from time import sleep

def convert_to_seconds(time_str):
    # 分割字符串获取分钟和秒
    parts = time_str.split('分')
    minutes = int(parts[0])  # 将分钟转换为整数
    seconds = int(parts[1].replace('秒', ''))  # 移除"秒"并转换为整数

    # 将分钟转换为秒，并加上秒
    total_seconds = minutes * 60 + seconds
    return total_seconds


# 指定 ChromeDriver 的路径
driver_path = 'd:/code_zgq/ganbu/chromedriver.exe'
service = Service(executable_path=driver_path)

# 创建 WebDriver 实例
driver = webdriver.Chrome(service=service)
# driver = webdriver.Chrome()



driver.implicitly_wait(3)
driver.maximize_window()

# 打开网页
driver.get('https://www.sxgbxx.gov.cn/login')

# 等待页面加载完成
wait = WebDriverWait(driver, 10)

# 找到用户名输入框并输入用户名
username_input = wait.until(EC.presence_of_element_located((By.ID, 'userEmail')))
username_input.send_keys('u0122092')

# 找到密码输入框并输入密码
password_input = wait.until(EC.presence_of_element_located((By.ID, 'userPassword')))
password_input.send_keys('071726zgq001!')

# 提示用户输入验证码
# print("按回车继续...")
input("按回车继续...")

# driver.get("https://www.sxgbxx.gov.cn/")
# zuanti_1 = driver.find_element(By.CSS_SELECTOR,"#aCoursesList > div.container > div.mt30.m-top-box.tzc_zt_dbox > div.net-cou-box > ul > li:nth-child(1) > div > a > div > img").click()
# start =zuanti_1.find_element(By.CSS_SELECTOR,"#aCoursesList > div > div.i-box.clearfix.pr.of.mt20.m-video-box > article.fl.c-a-wrap.cou-a-wrap > div > div.mt20.clearfix.of > div > a").click()
# continew = start.find_element(By.CSS_SELECTOR,"body > div.in-wrap > div.nxb-box.ucenter-box > div.bg-fa.of > section.container > div > div > article > div.i-box.mt20 > section > div.p-l-wrap > div > div.p-cou-wrap.p-l-module > ul > li:nth-child(1) > aside > a").click()
# see = continew.find_element(By.CSS_SELECTOR,"#aCoursesList > div > div.i-box.clearfix.pr.of.mt20.m-video-box > article.fl.c-a-wrap.cou-a-wrap > div > div.mt20.clearfix.of > div > a").click()
driver.get("https://www.sxgbxx.gov.cn/front/playkpoint/870a4f1201e8d51e")
# driver.get(url)
# 得到文件列表,a.play-icon-box 12个图文+视频，a.play-icon-box.image-icon-box，9个，图文
# articles = driver.find_elements(By.CSS_SELECTOR, "div.n-ct-of > div a.play-icon-box.image-icon-box")
# articles = driver.find_elements(By.CSS_SELECTOR, "div.n-ct-of > div a.play-icon-box")
articles = driver.find_elements(By.CSS_SELECTOR, "div.n-ct-of > div")
# articles = driver.find_elements(By.CSS_SELECTOR, "div.n-ct-of > div a.c-p-title")
# div.n-ct-of > div a.c-p-title
print(articles)
# 点击后，再判断，如果是图文，sleep(10)，如果是视频，再点播放


# 在循环中等待元素出现
for article in articles:
    item = article.find_element(By.CSS_SELECTOR,"a.play-icon-box").click()

    # 判断是图文还是视频

    if item.get_attribute("title") == "图文播放":
        sleep(10)
        print("图文**************************")
    elif item.get_attribute("title") == "视频播放":
        sleep(20)
        print("视频&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")







